package com.example.springboot.service.impl;

import com.example.springboot.controller.request.RoomPageRquest;
import com.example.springboot.entity.Room;
import com.example.springboot.mapper.RoomMapper;
import com.example.springboot.service.IRoomService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoomService implements IRoomService {

    @Autowired
    RoomMapper roomMapper;

    @Override
    public List<Room> listRooms() {
        return roomMapper.listRooms();
    }

    @Override
    public void add(Room room) {
        roomMapper.add(room);
    }

    @Override
    public void delete(Room room) {
        roomMapper.delete(room);
    }

    @Override
    public Object page(RoomPageRquest roomPageRquest) {
        PageHelper.startPage(roomPageRquest.getPageNum(), roomPageRquest.getPageSize());
        List<Room> rooms = roomMapper.listByCondition(roomPageRquest);
//        roomMapper.listByCondition(roomPageRquest);
        return new PageInfo<>(rooms);
    }

    @Override
    public Room getById(String roomid) {
        return roomMapper.getById(roomid);
    }

    @Override
    public void update(Room room) {
        roomMapper.updateById(room);
    }

}
